package com.calm.cdemo.anim;

import android.animation.ValueAnimator;
import android.view.View;
import android.widget.TextView;

import com.calm.cdemo.R;
import com.calm.cdemo.base.BaseActivity;

/**
 * Create by Calm
 * 2020/3/5 16:31
 */
public class ValueAnim extends BaseActivity implements View.OnClickListener {
    private TextView tvText;
    @Override
    protected void init() {
        tvText = findViewById(R.id.valueanim_tv_text);
        findViewById(R.id.valueanim_btn_start).setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.valueanim;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.valueanim_btn_start:
                doValueAnim();
                break;
        }
    }
    private void doValueAnim(){
        ValueAnimator animator = ValueAnimator.ofInt(0,200);
        animator.setDuration(2000);
        //添加监听来接收动画中的值
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                final int curValue = (int)valueAnimator.getAnimatedValue();
                tvText.setText(String.valueOf(curValue));
            }
        });
        animator.start();
    }
}
